package com.zm.zmgz.controller.businessdata;

import com.zm.zmgz.annotationzm.ButtonAuthorityAnnotation;
import com.zm.zmgz.pojo.ProjectProfitBatchOptionBean;
import com.zm.zmgz.pojo.ProjectProfitBean;
import com.zm.zmgz.pojo.Response;
import com.zm.zmgz.service.ProjectProfitService;
import com.zm.zmgz.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: cjw
 * @Date: 2020/05/13/11:01
 * @Description:项目盈利模块
 */
@RestController
@RequestMapping("/businessdata/projectprofit")
public class ProjectProfitController {
    @Autowired
    ProjectProfitService projectProfitService;

    /***
     * @Description: 通过日期刷新该批次的项目盈利数据
     * @Param:
     * @return:
     * @Author: cjw
     * @Date: 2020-04-22 17:42:03
     */
    @ButtonAuthorityAnnotation("/revenue/incomeAndExpenditureDetails/refreshTheBatch")
    @PostMapping("/refreshProjectProfitByDate")
    public Response refreshProjectProfitByDate(@RequestHeader("X-Token") String token, String date) {
        System.err.println(date);
        Date date1 = DateUtils.getDateByString(date,"yyyy年MM月");
        boolean b = projectProfitService.refreshProjectProfit(date1);
        return b ? new Response(20000, "项目盈利数据刷新成功!", true) : new Response(20000, "项目盈利数据刷新失败!", false);
    }

    /***
     * @Description: 获取批次选择数据(年月)
     * @Param:
     * @return:
     * @Author: cjw
     * @Date: 2020-04-22 17:42:03
     */
    @GetMapping("/getBatchOptions")
    public Response getBatchOptions() {
        List<ProjectProfitBatchOptionBean> list = projectProfitService.getBatchOptions();
        return !Objects.isNull(list) ? new Response(20000, "获取批次选择数据成功!", list) : new Response(20000, "获取批次选择数据失败!", null);
    }

    /***
     * @Description: 提供日期获取项目盈利数据
     * @Param:
     * @return:
     * @Author: cjw
     * @Date: 2020-04-22 17:42:03
     */
    @GetMapping("/getProjectProfitByDate")
    public Response getProjectProfitByDate(String date, Integer page, Integer limit) {
        System.err.println(date);
        Date date1 = DateUtils.getDateByString(date,"yyyy年MM月");
        List<ProjectProfitBean>  profitBeanList = projectProfitService.getBatchByDate(date1,page,limit);
        return !Objects.isNull(profitBeanList) ? new Response(20000, "获取项目盈利数据成功!", profitBeanList) : new Response(20000, "获取项目盈利数据失败!", null);
    }

}
